options nocenter ls=max ps=max;
libname mmo9601 "\\casd.fr\casdfs\Projets\INEPROG\Data\MMO_DMMO_1996-2001";
libname mmo9600 "\\casd.fr\casdfs\Projets\INEPROG\Data\MMO_MMO_1996-2000";
libname mmo0114 "\\casd.fr\casdfs\Projets\INEPROG\Data\MMO_MMO_2001-2014";
libname mmo18 "\\casd.fr\casdfs\Projets\INEPROG\Data\MMO_MMO_version_2018";
libname rec "C:\Users\Public\Documents\Results\Layoffs";


data mouvements_1517; 
set 
mmo18.mouvements_0115 (where=(annee="2015") DROP=DATEENT)
mmo18.mouvements_072015 (rename=(nation=nation2))
mmo18.mouvements_082015 (rename=(nation=nation2))
mmo18.mouvements_092015 (rename=(nation=nation2))
mmo18.mouvements_102015 (rename=(nation=nation2))
mmo18.mouvements_112015 (rename=(nation=nation2))
mmo18.mouvements_122015 (rename=(nation=nation2))


mmo18.mouvements_012016 (rename=(nation=nation2))
mmo18.mouvements_022016 (rename=(nation=nation2))
mmo18.mouvements_032016 (rename=(nation=nation2))
mmo18.mouvements_042016 (rename=(nation=nation2))
mmo18.mouvements_052016 (rename=(nation=nation2))
mmo18.mouvements_062016 (rename=(nation=nation2))
mmo18.mouvements_072016 (rename=(nation=nation2))
mmo18.mouvements_082016 (rename=(nation=nation2))
mmo18.mouvements_092016 (rename=(nation=nation2))
mmo18.mouvements_102016 (rename=(nation=nation2))
mmo18.mouvements_112016 (rename=(nation=nation2))
mmo18.mouvements_122016 (rename=(nation=nation2))


mmo18.mouvements_012017 (rename=(nation=nation2))
mmo18.mouvements_022017 (rename=(nation=nation2))
mmo18.mouvements_032017 (rename=(nation=nation2))
mmo18.mouvements_042017 (rename=(nation=nation2))
mmo18.mouvements_052017 (rename=(nation=nation2))
mmo18.mouvements_062017 (rename=(nation=nation2))
mmo18.mouvements_072017 (rename=(nation=nation2))
mmo18.mouvements_082017 (rename=(nation=nation2))
mmo18.mouvements_092017 (rename=(nation=nation2))
mmo18.mouvements_102017 (rename=(nation=nation2))
mmo18.mouvements_112017 (rename=(nation=nation2))
mmo18.mouvements_122017 (rename=(nation=nation2))
;
FORMAT _ALL_;
INFORMAT _ALL_;

if annee=. then annee=YEAR(date_stat);

/*if typees="" then typees=COMPRESS(ctt_motif_fin);
if nation="" and nation2="01" then nation="F";
else if nation="" and nation2 in ("02","03") then nation="C";
else if nation="" and nation2 in ("04","99","") then nation="A";*/

keep annee siret typees nation sexe nation2 ctt_motif_fin;
run;



proc sql; 
create table m1517 as select 
min(siret) as siret,
min(annee) as year,
sum(typees in ("FD","DM","CO","LE","LA","PR","ES","TS","OF","FN","FE","AU") 
	OR  ctt_motif_fin in ("FD","DM","CO","LE","LA","PR","ES","TS","OF","FN","FE","AU")) as nbexits,
sum(typees="LA" OR  ctt_motif_fin="LA") as nbotherlayoffs,
sum(typees="LE" OR  ctt_motif_fin="LE") as nblayoffs,
sum((typees="LE" OR  ctt_motif_fin="LE")
	and (nation in ("C","A","01","02","03","04") or nation2 in ("C","A","01","02","03","04"))) as nbforlayoffs,
sum((typees="LE" OR  ctt_motif_fin="LE") and sexe in ("F")) as nbfemlayoffs,
sum(typees="TS" OR  ctt_motif_fin="TS") as nbtransfers
from mouvements_1517 group by siret, annee;


create table m0114 as select 
min(siret) as siret,
min(annee) as year,
sum(typees in ("FD","DM","CO","LE","LA","PR",
"ES","TS","OF","FN","FE","AU")) as nbexits,
sum(typees="LA") as nbotherlayoffs,
sum(typees="LE") as nblayoffs,
sum(typees="LE" and nation in ("C","A")) as nbforlayoffs,
sum(typees="LE" and sexe in ("F")) as nbfemlayoffs,
sum(typees="TS") as nbtransfers
from mmo18.mouvements_0115 (where=(annee<"2015")) group by siret, annee;

create table m9800 as select 
min(siret) as siret,
min(annee) as year,
sum(typees in ("FD","DM","LE","LA",
"ES","TS","AU")) as nbexits,
sum(typees="LA") as nbotherlayoffs,
sum(typees="LE") as nblayoffs,
sum(typees="LE" and nation in ("C","A")) as nbforlayoffs,
sum(typees="LE" and sexe in ("F")) as nbfemlayoffs,
sum(typees="TS") as nbtransfers
from mmo18.mouvements_9800 group by siret, annee;

create table m9397 as select 
min(siret) as siret,
min(annee) as year,
sum(typees in ("FD","DM","LE","LA",
"ES","TS","AU","SI")) as nbexits,
sum(typees="LA") as nbotherlayoffs,
sum(typees="LE") as nblayoffs,
sum(typees="LE" and nation in ("C","A")) as nbforlayoffs,
sum(typees="LE" and sexe in ("F")) as nbfemlayoffs,
sum(typees="TS") as nbtransfers
from mmo18.mouvements_9397 group by siret, annee;
quit;


data etab_1517; 
set 
mmo18.etab_0115 (where=(annee="2015") )
mmo18.etab_072015
mmo18.etab_082015
mmo18.etab_092015
mmo18.etab_102015
mmo18.etab_112015
mmo18.etab_122015

mmo18.etab_012016 
mmo18.etab_022016 
mmo18.etab_032016 
mmo18.etab_042016 
mmo18.etab_052016 
mmo18.etab_062016 
mmo18.etab_072016 
mmo18.etab_082016 
mmo18.etab_092016 
mmo18.etab_102016 
mmo18.etab_112016 
mmo18.etab_122016 


mmo18.etab_012017 
mmo18.etab_022017 
mmo18.etab_032017 
mmo18.etab_042017 
mmo18.etab_052017 
mmo18.etab_062017 
mmo18.etab_072017 
mmo18.etab_082017 
mmo18.etab_092017 
mmo18.etab_102017 
mmo18.etab_112017 
mmo18.etab_122017 


;
if annee=. then annee=YEAR(DATE_STAT);
run;



proc sql; 
create table e1517 as select 
min(siret) as siret,
min(annee) as year,
max(effref) as effref,
max(eff) as effref2,
mean(pdsstrat) as pdsstrat,
mean(pds) as pds,
mean(pds_finaux) as pds2
from etab_1517 group by siret, annee;

create table e0114 as select 
min(siret) as siret,
min(annee) as year,
max(effref) as effref,
mean(pdsstrat) as pdsstrat,
mean(pds) as pds
from mmo18.etab_0115 (where=(annee<"2015")) group by siret, annee;

create table e9800 as select 
min(siret) as siret,
min(annee) as year,
max(effref) as effref,
mean(pdsstrat) as pdsstrat,
mean(pds) as pds
from mmo18.etab_9800 group by siret, annee;

create table e9397 as select 
min(siret) as siret,
min(annee) as year,
max(effref) as effref,
/*mean(pdsstrat) as pdsstrat,*/
mean(pds) as pds
from mmo18.etab_9397 group by siret, annee;
quit;

data layoffs; set m1517 m0114 m9800 m9397 ;
year=year*1;
if year<100 then year=1900+year;
run;

data size; set e1517 e0114 e9800 e9397 ; 
year=year*1;
if year<100 then year=1900+year;
if effref=. then effref=effref2;

if pds ne . and pds2 ne . then pds=(pds+pds2)/2;
else if pds = . and pds2 ne . then pds=pds2;
drop pds2 effref2;
run;

data rec.etab_mmo; set size; run;

proc sql; create table layoffs2 as select * from 
layoffs as aa left join size as bb on aa.siret=bb.siret and aa.year=bb.year;


libname rec2 "C:\Users\Public\Documents\Results\Establishment_Composition\";
libname e93 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_1993";
libname e94 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_1994";
libname e95 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_1995";
libname e96 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_1996";
libname e97 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_1997";
libname e98 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_1998";
libname e99 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_1999";
libname e00 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2000";
libname e01 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2001";
libname e02 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2002";
libname e03 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2003";
libname e04 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2004";
libname e05 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2005";
libname e06 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2006";
libname e07 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2007";
libname e08 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2008";
libname e09 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2009";
libname e10 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2010";
libname e11 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2011";
libname e12 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2012";
libname e13 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2013";
libname e14 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2014";
libname e15 "\\casd.fr\casdfs\Projets\INEPROG\Data\DADS_DADS Etablissements_2015";

 
data e93; set 
E93.etab1193 (keep=COM DEP NIC SIREN) 
E93.etab2193 (keep=COM DEP NIC SIREN) 
E93.etab2293 (keep=COM DEP NIC SIREN) 
E93.etab2393 (keep=COM DEP NIC SIREN) 
E93.etab2493 (keep=COM DEP NIC SIREN) 
E93.etab2593 (keep=COM DEP NIC SIREN) 
E93.etab2693 (keep=COM DEP NIC SIREN) 
E93.etab3193 (keep=COM DEP NIC SIREN) 
E93.etab4193 (keep=COM DEP NIC SIREN) 
E93.etab4293 (keep=COM DEP NIC SIREN) 
E93.etab4393 (keep=COM DEP NIC SIREN) 
E93.etab5293 (keep=COM DEP NIC SIREN) 
E93.etab5393 (keep=COM DEP NIC SIREN) 
E93.etab5493 (keep=COM DEP NIC SIREN) 
E93.etab7293 (keep=COM DEP NIC SIREN) 
E93.etab7393 (keep=COM DEP NIC SIREN) 
E93.etab7493 (keep=COM DEP NIC SIREN) 
E93.etab8293 (keep=COM DEP NIC SIREN) 
E93.etab8393 (keep=COM DEP NIC SIREN) 
E93.etab9193 (keep=COM DEP NIC SIREN) 
E93.etab9393 (keep=COM DEP NIC SIREN) 
E93.etab9493 (keep=COM DEP NIC SIREN) 
E93.etab9793 (keep=COM DEP NIC SIREN) ;
year=1993; COMT=DEP!!COM; DROP DEP COM;run;

data e94; set 
E94.etab0094 (keep=COM DEP NIC SIREN) 
E94.etab1194 (keep=COM DEP NIC SIREN) 
E94.etab2194 (keep=COM DEP NIC SIREN) 
E94.etab2294 (keep=COM DEP NIC SIREN) 
E94.etab2394 (keep=COM DEP NIC SIREN) 
E94.etab2494 (keep=COM DEP NIC SIREN) 
E94.etab2594 (keep=COM DEP NIC SIREN) 
E94.etab2694 (keep=COM DEP NIC SIREN) 
E94.etab3194 (keep=COM DEP NIC SIREN) 
E94.etab4194 (keep=COM DEP NIC SIREN) 
E94.etab4294 (keep=COM DEP NIC SIREN) 
E94.etab4394 (keep=COM DEP NIC SIREN) 
E94.etab5294 (keep=COM DEP NIC SIREN) 
E94.etab5394 (keep=COM DEP NIC SIREN) 
E94.etab5494 (keep=COM DEP NIC SIREN) 
E94.etab7294 (keep=COM DEP NIC SIREN) 
E94.etab7394 (keep=COM DEP NIC SIREN) 
E94.etab7494 (keep=COM DEP NIC SIREN) 
E94.etab8294 (keep=COM DEP NIC SIREN) 
E94.etab8394 (keep=COM DEP NIC SIREN) 
E94.etab9194 (keep=COM DEP NIC SIREN) 
E94.etab9394 (keep=COM DEP NIC SIREN) 
E94.etab9494 (keep=COM DEP NIC SIREN) 
E94.etab9794 (keep=COM DEP NIC SIREN) ;
year=1994; COMT=DEP!!COM; DROP DEP COM;run;

data e95; set 
E95.eta0095 (keep=COM DEP NIC SIREN) 
E95.eta1195 (keep=COM DEP NIC SIREN) 
E95.eta2195 (keep=COM DEP NIC SIREN) 
E95.eta2295 (keep=COM DEP NIC SIREN) 
E95.eta2395 (keep=COM DEP NIC SIREN) 
E95.eta2495 (keep=COM DEP NIC SIREN) 
E95.eta2595 (keep=COM DEP NIC SIREN) 
E95.eta2695 (keep=COM DEP NIC SIREN) 
E95.eta3195 (keep=COM DEP NIC SIREN) 
E95.eta4195 (keep=COM DEP NIC SIREN) 
E95.eta4295 (keep=COM DEP NIC SIREN) 
E95.eta4395 (keep=COM DEP NIC SIREN) 
E95.eta5295 (keep=COM DEP NIC SIREN) 
E95.eta5395 (keep=COM DEP NIC SIREN) 
E95.eta5495 (keep=COM DEP NIC SIREN) 
E95.eta7295 (keep=COM DEP NIC SIREN) 
E95.eta7395 (keep=COM DEP NIC SIREN) 
E95.eta7495 (keep=COM DEP NIC SIREN) 
E95.eta8295 (keep=COM DEP NIC SIREN) 
E95.eta8395 (keep=COM DEP NIC SIREN) 
E95.eta9195 (keep=COM DEP NIC SIREN) 
E95.eta9395 (keep=COM DEP NIC SIREN) 
E95.eta9495 (keep=COM DEP NIC SIREN) 
E95.eta9795 (keep=COM DEP NIC SIREN) ;
year=1995; COMT=DEP!!COM; DROP DEP COM;run;


data e96; set 
E96.eta0096 (keep=COM DEP NIC SIREN) 
E96.eta1196 (keep=COM DEP NIC SIREN) 
E96.eta2196 (keep=COM DEP NIC SIREN) 
E96.eta2296 (keep=COM DEP NIC SIREN) 
E96.eta2396 (keep=COM DEP NIC SIREN) 
E96.eta2496 (keep=COM DEP NIC SIREN) 
E96.eta2596 (keep=COM DEP NIC SIREN) 
E96.eta2696 (keep=COM DEP NIC SIREN) 
E96.eta3196 (keep=COM DEP NIC SIREN) 
E96.eta4196 (keep=COM DEP NIC SIREN) 
E96.eta4296 (keep=COM DEP NIC SIREN) 
E96.eta4396 (keep=COM DEP NIC SIREN) 
E96.eta5296 (keep=COM DEP NIC SIREN) 
E96.eta5396 (keep=COM DEP NIC SIREN) 
E96.eta5496 (keep=COM DEP NIC SIREN) 
E96.eta7296 (keep=COM DEP NIC SIREN) 
E96.eta7396 (keep=COM DEP NIC SIREN) 
E96.eta7496 (keep=COM DEP NIC SIREN) 
E96.eta8296 (keep=COM DEP NIC SIREN) 
E96.eta8396 (keep=COM DEP NIC SIREN) 
E96.eta9196 (keep=COM DEP NIC SIREN) 
E96.eta9396 (keep=COM DEP NIC SIREN) 
E96.eta9496 (keep=COM DEP NIC SIREN) 
E96.eta9796 (keep=COM DEP NIC SIREN) ;
year=1996; COMT=DEP!!COM; DROP DEP COM;run;


data e97; set e97.eta97 (keep=COM DEP NIC SIREN); year=1997; COMT=DEP!!COM; DROP DEP COM;run;
data e98; set e98.eta98 (keep=COM DEP NIC SIREN); year=1998; COMT=DEP!!COM; DROP DEP COM;run;
data e99; set e99.eta99 (keep=COM DEP NIC SIREN); year=1999; COMT=DEP!!COM; DROP DEP COM;run;
data e00; set e00.eta00 (keep=COM DEP NIC SIREN); year=2000; COMT=DEP!!COM; DROP DEP COM;run;
data e01; set e01.eta01 (keep=COM DEP NIC SIREN); year=2001; COMT=DEP!!COM; DROP DEP COM; run;

data e02; set e02.eta (keep=COMT NIC SIREN); year=2002; run;
data e03; set e03.eta (keep=COMT NIC SIREN); year=2003; run;
data e04; set e04.eta (keep=COMT NIC SIREN); year=2004; run;
data e05; set e05.eta (keep=COMT NIC SIREN); year=2005; run;
data e06; set e06.eta (keep=COMT NIC SIREN); year=2006; run;
data e07; set e07.eta (keep=COMT NIC SIREN); year=2007; run;
data e08; set e08.eta (keep=COMT NIC SIREN); year=2008; run;
data e09; set e09.eta (keep=COMT NIC SIREN); year=2009; run;
data e10; set e10.eta (keep=COMT NIC SIREN); year=2010; run;
data e11; set e11.detaesas (keep=COMT NIC SIREN); year=2011; run;
data e12; set e12.eta (keep=COMT NIC SIREN); year=2012; run;
data e13; set e13.eta (keep=COMT NIC SIREN); year=2013; run;
data e14; set e14.eta (keep=COMT NIC SIREN); year=2014; run;
data e15; set e15.eta (keep=COMT NIC SIREN); year=2015; run;

data etab; set e11 e93-e99 e00-e10 e12-e15; 
length siret $14.;
if year<2002 then siret=compress(substr(SIREN,2,9)!!substr(NIC,2,5));
else siret=compress(SIREN!!NIC);
*drop siren nic;
year2=compress(""!!year!!"");
drop year;
run;

proc sql; 
	create table layoffs3 
	as select * from layoffs2 as aa 
	left join etab as bb 
	on substr(aa.siret,1,14)=substr(bb.siret,1,14) and aa.year=bb.year2;
quit;

proc sql;
create table towns as select 
sum(COMT NE "" ) as nbwtown,
min(COMT) as wtown_mod,
min(siret) as siret
from layoffs3 group by siret;
quit;

proc sort data=towns; 
by siret nbwtown;
run;

data towns; set towns;
by siret;
if last.siret;
run;

proc sql; 
	create table layoffs4
	as select * from layoffs3 as aa 
	left join towns as bb 
	on aa.siret=bb.siret ;
quit;

data layoffs5; set layoffs4; 
if comt ="" than comt=wtown_mod;
run;


data est ; 
set 
rec2.b2010est (keep=est year WTOWN )
rec2.b1994est (keep=est year WTOWN )
rec2.b1995est (keep=est year WTOWN )
rec2.b1996est (keep=est year WTOWN )
rec2.b1997est (keep=est year WTOWN )
rec2.b1998est (keep=est year WTOWN )
rec2.b1999est (keep=est year WTOWN )
rec2.b2000est (keep=est year WTOWN )
rec2.b2001est (keep=est year WTOWN )
rec2.b2002est (keep=est year WTOWN )
rec2.b2003est (keep=est year WTOWN )
rec2.b2004est (keep=est year WTOWN )
rec2.b2005est (keep=est year WTOWN )
rec2.b2006est (keep=est year WTOWN )
rec2.b2007est (keep=est year WTOWN )
rec2.b2008est (keep=est year WTOWN )
rec2.b2009est (keep=est year WTOWN )
rec2.b2011est (keep=est year WTOWN )
rec2.b2012est (keep=est year WTOWN )
rec2.b2013est (keep=est year WTOWN )
rec2.b2014est (keep=est year WTOWN )
rec2.b2015est (keep=est year WTOWN )
rec2.b2016est (keep=est year WTOWN )
;
if year=1993.1 then year=1993;
year2=compress(""!!year!!"");
drop year;
run;

data est2; set est; 
length siret $14.;
if year2<"2002" then siret=substr(compress(est),2,9)!!substr(compress(est),12,5); 
else siret=compress(est);
run;

proc sql; 
	create table layoffs6 
	as select * from layoffs5 as aa 
	left join est2 as bb 
	on substr(aa.siret,1,13)=substr(bb.siret,1,13) and aa.year=bb.year2;
quit;


proc import file="\\casd\casdfs\LibreAcces\Base Sirene des entreprises et de leurs �tablissements - Stock au 1er janvier\Stock au 1er janvier 2018\sirc-17804_9075_14209_201712_L_M_20180104_040206250.csv"
out=siren17
dbms=dlm;
delimiter=";"
;
getnames=yes;
run;

data siren17_B; set siren17 (keep=DEPET COMET SIREN NIC);
run;

data siren17_C; set siren17_B ;
COMT2=COMPRESS(DEPET)!!COMPRESS(COMET);
SIRET=COMPRESS(SIREN)!!COMPRESS(NIC);
run;

proc sql; 
	create table layoffs7 
	as select * from layoffs6 as aa 
	left join SIREN17_C (DROP=SIREN NIC DEPET COMET) as bb 
	on aa.siret=bb.siret;
quit;

data layoffs8; set layoffs7;
if COMT="" and WTOWN NE "" then comt=wtown;
else if COMT="" and WTOWN ="" then comt=COMT2;
drop siren nic year2 nbwtown wtown_mod est WTOWN COMT2 ;
run;

proc import file="C:\Users\Public\Documents\Og_prov\commune.xlsx"
out=canton2 
;
run;

proc sql; create table layoffs9 as select * from layoffs8 as aa
left join canton2 (keep=CODGEO CV) as bb
on aa.comt=bb.codgeo;
quit;

data layoffs10; set layoffs9;
if CV="" and substr(COMT,1,3) in ("132","693","751") then CV=COMT;
biget=(effref>=50); 
run;

data rec.layoffs; set layoffs10;
year=year*1;
if effref>0 then rlayoff=nblayoffs/effref;
layoffs0=(nblayoffs>0);
layoffs1=(rlayoff>=0.05 and nblayoffs>1);
layoffs2=(rlayoff>=0.10 and nblayoffs>4);
layoffs3=(rlayoff>=0.20 and nblayoffs>4);
layoffs4=(rlayoff>=0.20 and nblayoffs>9);
run;

proc sql; 
create table layoffs_ct as select
MIN(year) as year,
MIN(cv) as cv,
SUM(biget*(SIRET NE "")) as nbestab_big,
SUM(biget*effref) as nbeffref_big,
SUM(biget*nblayoffs) as nblayoffs_big,
MAX(biget*nblayoffs) as maxlayoffs_big,
SUM(biget*nbforlayoffs) as nbforlayoffs_big,
SUM(biget*nbfemlayoffs) as nbfemlayoffs_big,
SUM(biget*nbexits) as nbexits_big,
SUM(biget*nbotherlayoffs) as nbotherlayoffs_big,
SUM(effref) as nbeffref_all,
SUM((SIRET NE "")) as nbestab_all,
SUM(nblayoffs) as nblayoffs_all,
MAX(nblayoffs) as maxlayoffs_all,
SUM(nbforlayoffs) as nbforlayoffs_all,
SUM(nbfemlayoffs) as nbfemlayoffs_all,
SUM(nbexits) as nbexits_all,
SUM(nbotherlayoffs) as nbotherlayoffs_all
from layoffs10 group by year, CV;
quit;


data rec.layoffs_ct_xpt; set layoffs_ct;
keep CV YEAR nbeffref_big nbexits_big nblayoffs_big maxlayoffs_big nbeffref_all nbexits_all nblayoffs_all maxlayoffs_all;
if 0<nbeffref_big<5 then nbeffref_big=.;
if 0<nbexits_big<5 then nbexits_big=.;
if 0<nblayoffs_big<5 then nblayoffs_big=.;
if 0<maxlayoffs_big<5 then maxlayoffs_big=.;
if 0<nbeffref_all<5 then nbeffref_all=.;
if 0<nbexits_all<5 then nbexits_all=.;
if 0<nblayoffs_all<5 then nblayoffs_all=.;
if 0<maxlayoffs_all<5 then maxlayoffs_all=.;
run;
